
$(function() {
	Combox_Type();
	$("#AuthorityUser").click(function() {
	
		var id = getIdSelections('User', 'userId');
		if (id.length == 1) {
			$("#userId").val(id);
			$('#modalUser').modal('show');
		} else {
			toastr.warning("请选择一条记录进行操作!");
		}
	});
	
	$("#reserve").click(function() {
		var form = "#userAuthorFrom";
		var url = "../UserController/update.action";
		$.ajax({
			type : "POST",
			url : url,
			data :{
				"userId":$("#userId").val(),
				"userState":$("#UserRoleCombox").val(),
			},
			success : function(data) {
				$('#modalUser').modal('hide');
				 $('#User').bootstrapTable('refresh', {url: '../UserController/findByCondition.action'});  
				toastr.success("授权成功");
				
			},
			error : function(request) {
				toastr.error("授权失败");
			}
		});
	});



	function submitEmailadd(form, url, type) {
		
	}
});

function Combox_Type() {
	$.ajax({
		type : "POST",
		url : "../RoleController/findByCondition.action",
		data : null,
		success : function(data) {
			var html = "";
			$.each(JSON.parse(data), function(j, o) {
				html += '<option value="' + o.roleId + '">' + o.roleName
						+ '</option>';
			});
			$("#UserRoleCombox").html(html);
			
		},
		error : function(request) {
			toastr.error("多选框错误!");
		}
	});
}


function getIdSelections(type, parm) {
	return $.map($('#' + type).bootstrapTable('getSelections'), function(row) {
		return eval('row.' + parm);
	});
}
